﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using GaiNo.Core.Data;
using GaiNo.WS.Core.Models;
using GaiNo.Core.Helpers;
using GaiNo.Core.Extensions;
namespace GaiNo.WS.Core.Services
{
    public class Member : IMember
    {
        #region IUser 成员

        public int? ID
        {
            get
            {
                return Convert.ToInt32(UserTicket.ToStringArrery("|")[0]);
            }
        }

        public string Name
        {
            get { return UserTicket.ToStringArrery("|")[1]; }
        }

        public bool IsInRole(string role)
        {
            return AuthenticationHelper.IsInRole(role);
        }

        public bool IsAuthenticated
        {
            get { return AuthenticationHelper.IsAuthenticated; }
        }

        public IDictionary<string, object> AuthenticationValues
        {
            get { throw new NotImplementedException(); }
        }

        public bool Authentication(string user, string password)
        {
            throw new NotImplementedException();
        }

        public bool CheckPermission(string controller, string action)
        {
            throw new NotImplementedException();
        }

        public bool CheckPermission(string controller)
        {
            throw new NotImplementedException();
        }

        #endregion
        private string _ticket = string.Empty;
        public string UserTicket
        {
            get
            {
                if (_ticket.IsNullOrEmpty())
                    _ticket = AuthenticationHelper.Ticket;

                if (_ticket.IsNullOrEmpty())
                    throw new ArgumentNullException("No found the authentication ticket");

                return _ticket;
            }
        }

        #region IMember 成员

        public string Helloword
        {
            get { return "Hello word"; }
        }

        #endregion
    }
}


